/* DISCLAIMER
Original file written by Johnny on Flame.
This piece is protected by the GPLv3 License. Commercial uses of this should only happen with my consent.
JohnnyonFlame (a_t) Hotmail (d_o_t) com
----------------------------------------------------------
This class deals with Callbacks.

These are Functions called once an action is taken in the
menus, be it dealing with sliders or not.
----------------------------------------------------------*/

#include "callbacks.h"
#include "menu.h"
#include "settings.h"

#include <stdio.h>
#include <libxml/tree.h>

#include "SDL/SDL.h"

char *Concatenate(char *s1, char *s2) {
  int len = strlen(s1) + strlen(s2) + 1;
  char *c = (char *)malloc(len);
  strcpy(c, s1);
  strcat(c, s2);
  return c;
}

void Menu_Step(){
	if ((event.key.keysym.sym == SDLK_LCTRL)) {
		setDisplayMenu(display_menu->items[m_index].arga);
	}
}

void Menu_CMD(){
	if (event.key.keysym.sym == SDLK_LCTRL)
	system(display_menu->items[m_index].arga);
}

void Menu_BIN(){
	if (event.key.keysym.sym == SDLK_LCTRL) {
		CMD = display_menu->items[m_index].arga;
		if (display_menu->items[m_index].argb != NULL) PATH = display_menu->items[m_index].argb;
		isRunning = 0;
	}
}

void Menu_INT(){
	if (event.key.keysym.sym == SDLK_LCTRL) {
		xmlNodePtr node = display_menu->items[m_index].arga;
		printf("Node Name:%s\n", node->name);
	}
}

void* DRAW_Item(TTF_Font *f, char *c, int sel, int n){
	return TTF_RenderText_Solid(f , c, (sel) ? TTF_SELECTED_COLOR : TTF_COLOR);
}

void* DRAW_Item_INT(TTF_Font *f, char *c, int sel, int n){
	char buffer[12];
	sprintf(buffer, ": %i", xmlGetProp(display_menu->items[m_index].arga, "value"));	
	return TTF_RenderText_Solid(f , Concatenate(c, buffer), (sel) ? TTF_SELECTED_COLOR : TTF_COLOR);
}
